﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace DIT.Client.MVVM.Converter
{
    public class UlongStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ulong? ulongValue = (ulong?)value;
            return ulongValue.HasValue ? ulongValue.Value.ToString() : null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string ulongString = value as string;
            ulong ulongValue;
            if (UInt64.TryParse(ulongString, out ulongValue))
                return ulongValue;
            else
                return null;
        }
    }
}
